package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StatServiceImpl implements StatService{
    @Autowired
    UserMapper userMapper;

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderGoodsMapper orderGoodsMapper;

    @Override
    public OrderstatBean queryOrdergoodsStatBean() {
        //example是提供条件的
        OrderstatBean orderstatBean = new OrderstatBean();
        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("customers");
        columns.add("amount");
        columns.add("pcr");
        orderstatBean.setColumns(columns);

        orderstatBean.setRows(orderMapper.orderStat());


        return orderstatBean;
    }

    @Override
    public ProductstatBean queryProductsStatBean() {
        //example是提供条件的
        ProductstatBean productstatBean = new ProductstatBean();
        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("orders");
        columns.add("products");
        columns.add("amount");
        productstatBean.setColumns(columns);

        productstatBean.setRows(orderGoodsMapper.productStat());

        return productstatBean;
    }

    @Override
    public UserstatBean queryUserStatBean() {
        //example是提供条件的
        UserExample userExample = new UserExample();
        //and + 列名 + 条件
        UserExample.Criteria criteria = userExample.createCriteria();

        UserstatBean userstatBean = new UserstatBean();


        ArrayList<String> columns = new ArrayList<>();
        columns.add("day");
        columns.add("users");
        userstatBean.setColumns(columns);

        int user_count = userMapper.userTotal();
//        List<User> users = userMapper.selectCondition(userExample, "add_time");
        List<UserstatBean.RowsBean> rows = new ArrayList<>();
        rows.add(new UserstatBean.RowsBean().setUsers(user_count).setDay("2020-10-2"));
        userstatBean.setRows(rows);

        return userstatBean;
    }
}
